package rickyGame.ui
{
	import flash.display.Sprite;
	
	import rickyGame.ui.BaseView;
	import rickyGame.ui.Hall;
	import rickyGame.ui.loading.Loading;
	


	/**
	 * ui管理类
	 */
	public class UIManager
	{
		public function UIManager()
		{
//			_uiLayer=new Sprite();
		}
		
		public function set uiLayer(value:Sprite):void
		{
			_uiLayer = value;
		}

		public function get loading():Loading
		{
			return _loading;
		}

		public function set loading(value:Loading):void
		{
			_loading = value;
		}
		
		public function addLoadingToUILayer():void
		{
			_uiLayer.addChild(_loading);
		}
		
		public function removeLoading():void
		{
			if(loading && loading.parent)
				loading.parent.removeChild(loading);
		}

		/**
		 * 游戏主场景
		 */
		public  function get game():Sprite
		{
			return _game;
		}

		public  function set game(value:Sprite):void
		{
			_game = value;
		}

		/**
		 * 显示大厅
		 */
		public function showHall(bool:Boolean=true):void
		{
			if(!_hall)
			{
				_hall=new Hall();
				addChild(_hall);
			}
			
			_hall.visible=bool;
		}
		
		
		public function get hall():Hall
		{
			return _hall;
		}

		public function set hall(value:Hall):void
		{
			_hall = value;
		}

		public function addChild(baseview:BaseView):BaseView
		{
			baseview.initialize();
			uiLayer.addChild(baseview);
			return baseview;
		}
		
		
		public function addChildAt(baseview:BaseView,index:int):BaseView
		{
			baseview.initialize();
			uiLayer.addChildAt(baseview,index);
			return baseview;
		}
		
		/**
		 * ui层
		 */
		public function get uiLayer():Sprite
		{
			return _uiLayer;
		}
		
		//
		private var _uiLayer:Sprite;
		private var _hall:Hall;
		private var _game:Sprite;
		private var _loading:Loading;
		
		private static var _inst:UIManager;

		public static function get inst():UIManager
		{
			if(!_inst)
				_inst=new UIManager();
			return _inst;
		}
	}
}